package itheima.com.SocketApi;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
//客户端
public class SoketClienmt {

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);
        System.out.println("客户端 socket返回="+socket.getClass());

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("hello world".getBytes());
        socket.shutdownOutput();
//        获取输入流
        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024];
        int len =  0;
        while ((len = inputStream.read(buf))!= -1){
            System.out.println("读取服务器的"+new String(buf,0,len));
        }

        socket.shutdownInput();
//        socket.shutdownOutput();





        inputStream.close();
        socket.close();
        outputStream.close();
        System.out.println("客户端退出...........");

    }


}
